#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5, INF = 1e18;
int t, n, m, v, L, a, b, c;
pair <int, int> car[N];
int maxr, ans, q[N], s, ansnum;
signed main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> t;
    while (t--) {
        // init();
        s = ans = ansnum = 0;
        maxr = -INF * 2;
        cin >> n >> m >> L >> v;
        for (int i = 1; i <= n; i++) {
            scanf("%lld%lld%lld", &a, &b, &c);
            if (c > 0) {
                car[i].second = ((v + b) * (v - b)) / (2 * c) + a + 1;
                if (v < b) car[i].second = a;
                car[i].first = INF;
            }
            else if(c == 0) {
                if (b > v) car[i].second = a, car[i].first = INF;
                else car[i].first = car[i].second = INF;
            }
            else {
                car[i].second = a;
                car[i].first = a + ((v + b) * (v - b)) / (2 * c);
                if (b <= v) car[i].first = car[i].second = INF;
            }
        }
        for (int i = 1; i <= m; i++) cin >> q[i];
        sort (q + 1, q + m + 1);
        sort (car + 1, car + n + 1);
        q[0] = -INF * 2;
        q[m + 1] = INF * 2;
        for (int i = 1; i <= n; i++) {
            if (car[i].second > L) continue;
            if (maxr >= car[i].second) {
                ansnum++;
                continue;
            }
            while (q[s + 1] <= car[i].first && s <= m) s++;
            if (q[s] < car[i].second) 
                continue;
            ansnum++, ans++, maxr = q[s];
        }
        cout << ansnum << ' ' << m - ans << endl;
    }
    return 0;
}